package com.amphiprion.prototype.component.animation;

import com.amphiprion.prototype.component.SpriteComponent;

public class SpriteComponentAnimation extends GameComponentAnimation {
	private float interval = 0;

	public SpriteComponentAnimation(long duration, long delay, long pauseBeforeLoop, long pauseBeforeBackward) {
		this.delay = delay;
		this.pauseBeforeLoop = pauseBeforeLoop;
		this.pauseBeforeBackward = pauseBeforeBackward;
		this.duration = duration;
		loop = true;
		forwardAndBack = true;
	}

	@Override
	protected void onUpdate(float progress) {
		((SpriteComponent) cmp).setFrameIndex((int) ((progress * duration - 1) / interval));
	}

	@Override
	public void start() {
		interval = duration / ((SpriteComponent) cmp).getFrameCount();
	}

}
